package com.youhome.mobile.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.mobile.dto.DTOHotCity;
import com.youhome.service.model.HotCity;
import com.youhome.service.service.HotCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.modelmapper.ModelMapper;
import org.modelmapper.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by chen365 on 2018/09/13.
 */
@Api(tags = "城市")
@RestController
public class CityController {

    @Autowired
    private HotCityService hotCityService;

    @ApiOperation(value = "热门城市", notes = "热门城市", response = DTOHotCity.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping(value = "/cities/hot")
    public Object hot() throws CustomException {
        ModelMapper modelMapper = new ModelMapper();
        List<HotCity> hotCities = hotCityService.selectByEnabled(true);
        return new Result<>(ResultCode.SUCCESS, modelMapper.map(hotCities, new TypeToken<List<DTOHotCity>>() {
        }.getType()));
    }
}
